package com.example.f8399.testdemo.activity;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.databinding.DataBindingUtil;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Build;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;

import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.example.f8399.testdemo.BaseActivity;
import com.example.f8399.testdemo.R;
import com.example.f8399.testdemo.databinding.ActivityEmptyRcBinding;
import com.example.f8399.testdemo.service.StepCounterService;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @description .
 *
 * @author lcfeng
 * @date   2018/9/1 16:08.
**/
public class EmptyRcActivity extends BaseActivity {


    ActivityEmptyRcBinding mBinding;
    private AlarmManager mAlarmManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBinding = DataBindingUtil.setContentView(this,R.layout.activity_empty_rc);
        mBinding.setAc(this);


        initView();
    }

    private void initView() {

    }

    public void getElapsedTime(View view) {
        long l = System.currentTimeMillis() - SystemClock.elapsedRealtimeNanos() / 1000000;
        LogUtils.d("开机到现在：" + l);
        Date date = TimeUtils.millis2Date(l);
        LogUtils.d("开机到现在：" +TimeUtils.date2String(date,new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")) );

    }

    public void getStepCounter(View view) {
        Intent service = new Intent(this, StepCounterService.class);
        PendingIntent pendingIntent = PendingIntent.getService(this, 0,service,0);

        mAlarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

        mAlarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP,System.currentTimeMillis(),1000*2,pendingIntent);
    }

    public void showTime(View view) {
        long nowMills = TimeUtils.getNowMills();
        StringBuffer stringBuffer = new StringBuffer(TimeUtils.getNowString(new SimpleDateFormat("yyyy-MM-dd")));
        StringBuffer append = stringBuffer.append(" 23:59:59");
        long l = TimeUtils.string2Millis(append.toString());
        LogUtils.d(nowMills+"---"+l);
        LogUtils.d(l-nowMills);
    }
}
